package com.gitee.chili.leisure;

import javax.servlet.http.HttpServletRequest;

/**
 * AddrUtil
 *
 * @author week solider
 * @since 2020.09.04
 */
public class AddrUtil {

    public static String getAddr(HttpServletRequest request) {
        String ip = request.getRemoteAddr();
        String headerIP = request.getHeader("x-real-ip");
        if (headerIP == null || "".equals(headerIP) || "null".equals(headerIP)) {
            headerIP = request.getHeader("x-forwarded-for");
        }
        if (headerIP != null && !"".equals(headerIP) && !"null".equals(headerIP)) {
            ip = headerIP;
        }
        return ip;
    }
}
